import { Ref, ref } from "vue";
import { defineStore } from "pinia";
import { fetchTopCategoryAPI } from "@/api/categoryApi/categoryApi.ts";
import type { TopCategory } from "@/types/categoryTypes/categoryTypes.ts";
import { categoryStoreInterface } from "@/pinia/modules/categoryStore/interface.ts";

const useCategoryStore = defineStore("categoryStore", ():categoryStoreInterface => {
   /*一级类目列表*/
   const topCategoryList:Ref<TopCategory[]> = ref<TopCategory[]>([]);
   /*获取一级类目的请求函数*/
   const fetchTopCategory = async (id: string): Promise<void> => {
      const { result }: { result: TopCategory[] } = await fetchTopCategoryAPI(id);
      topCategoryList.value = result;
   };

   return {
      topCategoryList,
      fetchTopCategory,
   };
});


export default useCategoryStore;
